package cn.com.hhrcw.enterprise.job;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * @program: stdss-boot-parent
 * @author: JD
 * @create: 2020-07-23 15:19
 **/
@Configuration
public class EnConfig {

    @Autowired
    AdaptableJobFactory jobFactory;

    @Bean("EnIndirectFundsJobDetail")
    public JobDetailFactoryBean jobDetailFactoryBean(@Qualifier("EnJobStatisticsTask") EnJobStatisticsTask myQuartzJob) {
        JobDetailFactoryBean jobDetailFactoryBean = new JobDetailFactoryBean();
        jobDetailFactoryBean.setDurability(true);
        jobDetailFactoryBean.setJobClass(myQuartzJob.getClass());
        return jobDetailFactoryBean;
    }

    @Bean("EnIndirectFundsJobTrigger")
    public CronTriggerFactoryBean indirectFundsQuartzJobFactoryBean(@Qualifier("EnIndirectFundsJobDetail") JobDetailFactoryBean jobDetailFactoryBean) {
        CronTriggerFactoryBean triggerFactoryBean = new CronTriggerFactoryBean();
        triggerFactoryBean.setCronExpression("0 0/5 * * * ?");
        triggerFactoryBean.setJobDetail(jobDetailFactoryBean.getObject());
        return triggerFactoryBean;
    }

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean(@Qualifier("EnIndirectFundsJobTrigger") CronTriggerFactoryBean indirectFundsBean) {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setTriggers(indirectFundsBean.getObject());
        schedulerFactoryBean.setJobFactory(jobFactory);
        return schedulerFactoryBean;
    }
}
